package com.arrogames.blondbattle.game.graphics.ui 
{
	import com.arrogames.blondbattle.assets.AssetManager;
	import com.arrogames.blondbattle.game.state.event.GameOverEvent;
	import com.greensock.easing.Elastic;
	import com.greensock.TweenLite;
	import feathers.controls.Label;
	import starling.display.Button;
	import starling.display.Sprite;
	import starling.events.Event;
	
	/**
	 * ...
	 * @author ...
	 */
	public class GameOverDisplay extends Sprite {
		
		private var imageDisplay:Button;
		private var clickMeLabel:Label;
		
		public static const WIN:int = 1;
		public static const DRAW:int = 2;
		public static const LOSS:int = 3;
		
		public function GameOverDisplay(type:int) {
			super();
			
			if (type != WIN && type != DRAW && type != LOSS) {
				throw new Error("Unknown Gameover display type: " + type);
			}
			
			imageDisplay;
			
			if (type == WIN) {
				imageDisplay = new Button(AssetManager.instance.getTexture("WinBMP"));
			} else if (type == DRAW) {
				imageDisplay = new Button(AssetManager.instance.getTexture("DrawBmp"));
			} else if (type == LOSS) {
				imageDisplay = new Button(AssetManager.instance.getTexture("LostBMP"));
			}
			
			imageDisplay.alpha = 0;
			imageDisplay.scaleX = 0.1;
			imageDisplay.scaleY = 0.1;
			imageDisplay.pivotX = 150;
			imageDisplay.pivotY = 60;
			this.addChild(imageDisplay);
			
			this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}
		
		private function onAddedToStage(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
			
			TweenLite.to(
				imageDisplay, 
				2, 
				{alpha:1, scaleX:1, scaleY:1, ease:Elastic.easeOut }
			);
			
			imageDisplay.addEventListener(Event.TRIGGERED, onTriggered);
		}
		
		private function onTriggered(e:Event):void {
			imageDisplay.removeEventListener(Event.TRIGGERED, onTriggered);
			dispatchEvent(new GameOverEvent());
		}
		
	}

}